<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version = '1.0' 
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

    <xsl:output method="xml" indent="yes"/>
    <xsl:preserve-space elements="*"/>

    <xsl:template match='/'>
                <xsl:apply-templates select="gallery"/>
    </xsl:template>

    <xsl:template match='gallery'>
        <html><body>
                <xsl:apply-templates select="album"/>
        </body></html>
    </xsl:template>

    <xsl:template match='album'>
        <h1>
            <xsl:value-of select="@name"/>
            <xsl:text>:</xsl:text>
        </h1>
        <table>
            <xsl:for-each select="image[(position() mod 5 = 1) and (position() &lt; 9)]">
                <tr>
                  <xsl:apply-templates 
                   select=".|following-sibling::image[position() &lt; 5]"/>
               </tr>
            </xsl:for-each>
        </table>
    </xsl:template>

    <xsl:template match="image">
        <xsl:if test="position() &lt;= 4">
        <td>
        <img>
            <xsl:attribute name="src">
                <xsl:value-of select="path_t"/>
            </xsl:attribute> 
            <xsl:attribute name="alt">
                <xsl:value-of select="name"/>
            </xsl:attribute> 
        </img>
        </td>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>
